﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Manage/Views/Shared/Master.Master"
    Inherits="System.Web.Mvc.ViewPage<List<ELeaveWord>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <%
        foreach (var item in Model.Where(ii => ii.RId == 0))
        {
    %>
    <div class="leaveword">
        <div class="leavewordheader">
            <%=item.WriteTime.ToString("yyyy-MM-dd hh:mm:ss") + " " + item.Name%>
            留言
            <% if (item.Isvalid)
               { %>
            <input type="button" name="invalid" value=" 无效 " />
            <% }
               else
               { %>
            <input type="button" name="valid" value=" 有效 " />
            <% } %>
            <input type="button" name="reply" value=" 回复 " />
            <input type="button" name="deleteLeave" value=" 删除 " />
        </div>
        <%=Html.Hidden("lid", item.LId)%>
        <%=item.Content%>
        <%
            
            foreach (var innerItem in Model.Where(i => i.LId == item.LId && i.RId != 0))
            {
        %>
        <div class="reply">
            <strong>回复：</strong> <span class="b">
                <%=innerItem.Content %></span>
            <input type="button" name="editReply" value=" 修改 " />
            <input type="button" name="deleteReply" value=" 删除 " />
        </div>
        <%=Html.Hidden("rid", innerItem.RId)%>
        <%
            }
        %>
    </div>
    <% } %>
    <div class="divPager2" style="clear: both;">
        <%= Html.Pager(ViewData["Pager"]) %>
    </div>
    <div id="replyPost" class="hidden">
        <form method="post" action="<%=Url.Action("EditReply") %>">
        <textarea rows="5" cols="80" name="content" class="width300"></textarea>
        <input type="submit" value="保存" />
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cssLink" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="jsLink" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="cssContent" runat="server">
    <style type="text/css">
        .divPager2
        {
            text-align: center;
            clear: both;
            padding-top: 10px;
            padding-bottom: 4px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="jsContent" runat="server">
    <script type="text/javascript">
        $(function () {
            $("#replyPost form").ajaxForm(function () {
                location.reload();
            });
            $(":button[name='reply']").click(function () {
                $("#replyPost form").append($(this).parent().parent().find(":hidden[name='lid']").clone());
                // $("#replyPost form").append($(this).parent().parent().find(":hidden[name='rid']").clone());
                $("#replyPost").dialog({ title: "编辑回复", width: 320, close: function () { $(this).dialog("destroy") }, modal: true });
            });

            $(":button[name='editReply']").click(function () {
                $("#replyPost form").append($(this).parent().parent().find(":hidden[name='lid']").clone());
                $("#replyPost form").append($(this).parent().parent().find(":hidden[name='rid']").clone());
                $("#replyPost :input[name='content']").val($(this).parent().find(".b").text());
                $("#replyPost").dialog({ title: "编辑回复", width: 320, close: function () { $(this).dialog("destroy") }, modal: true });
            });


            $(":button[name='deleteLeave']").click(function () {
                if (confirm("删除提示!\n确定要删除吗")) {
                    var lid = $(this).parent().parent().find(":hidden[name='lid']").val();
                    $.post('<%=Url.Action("Delete") %>', { lid: lid }, function () { location.reload(); });
                }
            });
            $(":button[name='deleteReply']").click(function () {
                if (confirm("删除提示!\n确定要删除吗")) {
                    var rid = $(this).parent().parent().find(":hidden[name='rid']").val();
                    $.post('<%=Url.Action("Delete") %>', { lid: rid, flag: false }, function () { location.reload(); });
                }
            });
            $(":button[name='valid']").click(function () {
                var lid = $(this).parent().parent().find(":hidden[name='lid']").val();
                $.post('<%=Url.Action("SetState") %>', { lid: lid }, function () { location.reload(); });
            });
            $(":button[name='invalid']").click(function () {
                var lid = $(this).parent().parent().find(":hidden[name='lid']").val();
                $.post('<%=Url.Action("SetState") %>', { lid: lid, isvalid: false }, function () { location.reload(); });
            });
        });
    </script>
</asp:Content>
